A constant is a value which you put into your program. In the above expressions the values 2 and 1 are constants. You can give a constant as a number, in decimal, just by putting the number into the code:

i = i + 55 ;

This line of code will make the value i bigger by 55. The 55 is decimal (i.e. 5 tens and 5 units). However, C allows you a bit of flexibility when you put numbers into programs, depending on the easiest way of expressing them.

Octal - base 8

If you like you can use octal (i.e. base 8). To tell the compiler you are giving in an octal value you put a 0 in front of the value:

j = j + 050 ;

This line of code will make j bigger by 50 octal. Because in octal 50 means 5 eight's and no units this means that j will increase by 5*8, which is decimal 40. You can use octal where it is more convenient to do so, you are not required to use it, it is often used because it is easier to convert between octal and binary when you are working out bit patterns (of which more later)

Hexadecimal - base 16

You can also use the hexadecimal number scheme in your C programs. C can tell if a number is hex if you put the characters 0x in front of the value:

k = k + 0x25 ;

This would make k bigger by 25 hexadecimal. Because in hexadecimal 25 means 2 sixteen's and 5 units this means that k will increase by 37. Again, you use hex when it is easiest, usually when you have converted a number from binary to a hex value. Note that in hex the digits go 0123456789ABCDEF, where A means 10, B means 11 and so on.

ASCII Characters

Finally we can put ASCII characters into our C variables. ASCII stands for "American Standard Code for Information Interchange" and maps printing characters onto values. You will use these codes when you want to talk to the LCD panel, in that if we send the panel the ASCII code for the letter A it will draw an A on the screen for us. You can look these codes up if you like, and a table is provided for this, but you can also get the compiler to look the codes up for you. You ask the compiler to do this by putting the character you want the ASCII code for in single quotes:

ch = 'A' ;

This would set the variable ch to the ASCII code of 'A', which I happen to know is 65 decimal. If you use this technique (remembering to put a ' each side of the character and not to miss one out or use " by mistake) then you don't have to look up the character codes very often.

Note that the ASCII code is quite sensible, in that the ASCII code for 'B' is one bigger than the code for 'A', and the ASCII code for '1' is one bigger than the code for '0'. This means you can do cunning things like:

ch = '0' + b ;

This would set ch to the ASCII character which represents the digit which is held in the variable b. (note that if b holds a value bigger than 9 we are going to have problems here...)

It is perfectly OK to combine the different ways of putting constants into a program. The compiler doesn't care, but you must make sure that the combinations make sense, just like this one probably doesn't:

/*  legal but stupid  */
v = 'A' + 0x20 + 037 + 1 ;